package studio.raptor.ddal.dashboard.log.service.impl.mysql;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import studio.raptor.ddal.dashboard.log.bo.ConnPoolLogExtendData;
import studio.raptor.ddal.dashboard.log.bo.LogMessageObject;
import studio.raptor.ddal.dashboard.log.bo.SqlProcessLogExtendData;
import studio.raptor.ddal.dashboard.log.repository.ConnPoolLogRepository;
import studio.raptor.ddal.dashboard.log.repository.SqlProcessLogRepository;
import studio.raptor.ddal.dashboard.log.service.interfaces.ILogStorageService;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 类名称 LogStorageMysqlService<br>
 * 日志存取服务实现类-mysql实现
 * <hr>
 * 修改记录
 * <hr>
 * 1、修改人员:    修改时间:<br>       
 *    修改内容:
 * <hr>
 */
@Service
public class LogStorageMysqlService implements ILogStorageService {

	private static Logger log = LoggerFactory.getLogger(LogStorageMysqlService.class);

	@Resource
	private SqlProcessLogRepository sqlProcessLogRepository;
	@Resource
	private ConnPoolLogRepository connPoolLogRepository;

	@Override
	public void breakUpAndDBStorage(LogMessageObject logMessageObject) throws Exception {
		SqlProcessLogExtendData sqlProcessLogExtendData=logMessageObject.getSqlProcessLogExtendData();
		Date createTime=new Date();
		if(sqlProcessLogExtendData!=null){
			sqlProcessLogExtendData.setCreateTime(createTime  );
			log.debug("LogStorageMysqlService.class "+ "开始写入Mysql数据库--sqlProcessLogExtendData" +sqlProcessLogExtendData.getSql() );
			sqlProcessLogRepository.save( sqlProcessLogExtendData );
		}
		ConnPoolLogExtendData connPoolLogExtendData=logMessageObject.getConnPoolLogExtendData();
		if(connPoolLogExtendData!=null){
			connPoolLogExtendData.setCreateTime(createTime  );
			log.debug("LogStorageMysqlService.class "+ "开始写入Mysql数据库--connPoolLogExtendData"+connPoolLogExtendData.getPoolName() );
			connPoolLogRepository.save( connPoolLogExtendData );
		}
	}
}
